#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
	int n, m, *ntab, *mtab, q, i, from, to, c, a, b, l;
	scanf("%d", &n);
	ntab = malloc(sizeof(int) * (n + 1));
	for(i = 1; i <= n; i++) {
		scanf("%d", ntab + i);
	}
	scanf("%d", &m);
	mtab = malloc(sizeof(int) * (m + 1));
	for(i = 1; i <= m; i++) {
		scanf("%d", mtab + i);
	}
	scanf("%d", &q);
	while(q--) {
		scanf("%d %d %d", &a, &b, &l);
		from = 0;
		to = 0;
		c = 1;
		for(i = 0; i < l; i++) {
			if(ntab[i + a] != mtab[i + b]) {
				if((from == 0) && (to == 0)) {
					from = ntab[i + a];
					to = mtab[i + b];
				} else {
					if((from != ntab[i + a]) || (to != mtab[i + b]))
						c = 0;
				}
			} else {
				if(ntab[i + a] == from)
					c = 0;
			}
		}
		if(c == 1)
			printf("TAK\n");
		else
			printf("NIE\n");
	}
	return 0;
}
